<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript">
<%--        页面加载的时候干的事情   加载=>初始化=>完成=>用户看到--%>
        window.onload=function () {
            //1.当前学生的课程
            var course="${student.course}";//js中也可以写el表达式

            //2.1:选中
            document.getElementById("course").value=course;

            //2.2:获取学生的爱好
            var loves="${student.loves}";
            //按照","号拆分
            var lovesArrays = loves.split(",");
            //3.开始作选中
            //获取页面做选中
            let elementsByName = document.getElementsByName("loves");
            //遍历页面爱好框
            for (var i=0; i<elementsByName.length;i++) {
                for (var j=0; j<lovesArrays.length;j++) {
                    if(elementsByName[i].value==lovesArrays[j]){
                        elementsByName[i].checked=true;//选中
                    }

                }
            }

            //遍历当前学生的爱好

        }
    </script>
</head>
<body>
<h3>修改学生</h3>
<form method="post" action="http://localhost:8080/Student?action=update">
   <table border="1">
       <tr>
           <td>姓名:</td>
           <td>
               <input type="hidden" name="id" value="${student.id}">
               <input type="text" name="name" value="${student.name}">
           </td>
       </tr>
       <tr>
           <td>年龄:</td>
           <td>
               <input type="text" name="age" value="${student.age}">
           </td>
       </tr>
       <tr>
           <td>性别:</td>
           <td>
               <c:if test="${student.sex==1}">
                   <input type="radio" name="sex" value="1" checked>男
                   <input type="radio" name="sex" value="0" >女
               </c:if>
               <c:if test="${student.sex==0}">
                   <input type="radio" name="sex" value="1" >男
                   <input type="radio" name="sex" value="0" checked>女
               </c:if>
           </td>
       </tr>
       <tr>
           <td>手机号:</td>
           <td>
               <input type="text" name="phone" value="${student.phone}">
           </td>
       </tr>
       <tr>
           <td>邮箱:</td>
           <td>
               <input type="text" name="email" value="${student.email}">
           </td>
       </tr>
       <tr>
       <tr>
           <td>爱好:</td>
           <td>
               <input type="checkbox" name="loves" value="sing">唱
               <input type="checkbox" name="loves" value="jump">跳
               <input type="checkbox" name="loves" value="rap">rap
               <input type="checkbox" name="loves" value="basketball">篮球
           </td>
       </tr>
       <tr>
           <td>课程:</td>
           <td>
               <select name="course" id="course">
                   <option value="Java">Java从入门到放弃</option>
                   <option value="C++">C++入门基础</option>
                   <option value="Html">html基础教程</option>
                   <option value="Python">Python权威指南</option>
               </select>
           </td>
       </tr>
           <td colspan="2">
               <input type="submit" value="更新">
               <input type="reset" value="重置">
           </td>
       </tr>
   </table>
</form>

</body>
</html>
